var models = require('../models/user.js');
var moment = require('moment');
var forgetpwd = require('../models/forgetpwd.js').forgetpwd;
var ObjectId = require('mongoose').Types.ObjectId;
var menus = require('./menu').menu();
menus.forgetpwd.active = 'active';
module.exports.autoroute = {
	get:{
		'/admin/forget':function(req,res){
			res.render("forgetpwd",{menu:menus})
		},
		'/admin/forget/delete':function(req,res){
			var callback = function(err){
			  if(err){
			    debug(err);
			    res.send({code:-1,message:'保存失败'})
			  }else
			    res.redirect("/admin/forget");
			};
			forgetpwd.findByIdAndRemove(ObjectId(req.query.id),callback);
		},
		'/admin/ajax/forget':function(req,res){
			var page = 0;
			if(req.query.iDisplayStart)
				page = req.query.iDisplayStart;
			condition = {};
			if(req.query.username)
				condition.username = new RegExp(req.query.username);
			forgetpwd.find(condition).skip(page).limit(10).lean(true).exec(function(err,user){
				forgetpwd.find().count(function(err,size){
					user.forEach(function(item){
						item.create_time = moment(item.create_time).format("YYYY-MM-DD HH:mm");
					});
		  			res.json({aaData:user,iTotalRecords:size,iTotalDisplayRecords:size});
				})
			});
		},
	}
};

